package com.ftg.learn.assess.controller;

import com.ftg.learn.assess.dto.UserAddAssessDto;
import com.ftg.learn.assess.dto.UserAdditionalDto;
import com.ftg.learn.assess.result.Result;
import com.ftg.learn.assess.service.AdditionalService;
import com.ftg.learn.assess.service.AssessService;
import com.ftg.learn.assess.vo.UserGetAllAssessByEvaluationIdVo;
import com.ftg.learn.assess.vo.UserGetMeAssessVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/assess/user")
@Tag(name = "用户端评价模块")
@AllArgsConstructor
public class UserAssessController {
    @Autowired
    private final AssessService assessService;
    @Autowired
    private final AdditionalService additionalService;
    @PostMapping
    @Operation(summary = "用户评价")
    public Result<String> assess(@RequestBody UserAddAssessDto addAssessDto) {
        return additionalService.assess(addAssessDto);
    }
    @PostMapping("/add")
    @Operation(summary = "用户添加评价附加信息")
    public Result<String> addAdditional(@RequestBody UserAdditionalDto userAdditionalDto) {
        return additionalService.addAdditional(userAdditionalDto);
    }
    @DeleteMapping
    @Operation(summary = "用户删除评价")
    public Result<String> deleteAssess(@RequestParam("userId") Long userId,@RequestParam("evaluationId") Long evaluationId) {
        return assessService.removeAssessByUserId(userId, evaluationId);
    }
    @GetMapping("/me")
    @Operation(summary = "用户查看自己的评价")
    public Result<List<UserGetMeAssessVo>> getUserAssess(@RequestParam("userId") Long userId) {
        return assessService.getMeAssess(userId);
    }

    @GetMapping("/product")
    @Operation(summary = "用户查看某个商品的评价")
    public Result<List<UserGetAllAssessByEvaluationIdVo>> getProductAssess(@RequestParam("productId") Long productId) {
        return assessService.getProductAssessByEvaluationId(productId);
    }
    @GetMapping("/byMe")
    @Operation(summary = "用户查看自己评价的附加信息")
    public Result<String> getUserAssessByMe(@RequestBody UserAdditionalDto userAdditionalDto) {
        return additionalService.addAdditional(userAdditionalDto);
    }
    @GetMapping("/additional")
    @Operation(summary = "根据评价id获取所有追评信息")
    public Result<List<com.ftg.learn.assess.entity.Additional>> getAdditionalsByEvaluationId(@RequestParam("evaluationId") Long evaluationId) {
        return additionalService.getAdditionalsByEvaluationId(evaluationId);
    }

}
